package com.zzf.concurrent.example.sync.bean;

import com.zzf.concurrent.example.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author GaoFeng2017
 * @date 2019/8/6 9:31
 */

@Slf4j
public class OtherService implements Runnable {

    private final Object LOCK = new Object();

    private DeadLock deadLock;

    public OtherService(DeadLock deadLock) {
        this.deadLock = deadLock;
    }

    public Object getLOCK() {
        return LOCK;
    }

    @Override
    public void run() {
        while(true) {
            m1();
            TimeUtil.sleep(1);
        }
    }

    private void m1() {
        synchronized (LOCK) {
            log.info("m1=============");
            deadLock.s2();
        }
    }

    public void m2() {
        synchronized (LOCK) {
            log.info("m2==============");
        }
    }
}
